<template>
	<view class="content" v-if="idfd==1">
		<view class="main_content">
			<view class="page_content">
				<view class="bgsimg">
					<image src="/static/shilu-login/login_bgs.png" style="height: 490px;width: 385px;" mode=""></image>
				</view>
				<view class="head_content">
					<view class="title" style="text-align: center;font-size: 31px; color: #fff;">Rolling Short</view>
				</view>
				<view class="main_content">
					<view class="popup_wrap">
						<view class="head_box">
							<view class="title">
								登录
							</view>
						</view>
						<view class="list">
							<view class="list-call">
								<image class="img" src="/static/shilu-login/12.png"></image>
								<input class="sl-input" v-model="mobile" type="text" :placeholder="placeholdereml" />
							</view>
							<view class="list-call">
								<image class="img" src="/static/shilu-login/22.png"></image>
								<input class="sl-input" v-model="password" type="text" maxlength="32" :placeholder="placeholderpwd"
									password="true" />
							</view>
						</view>
						<view class="button-login" hover-class="button-hover" @tap="bindLogin()">
							<text style="font-size: 40upx;">{{$t('text.login')}}</text>
						</view>
						<view class="agreenment">
							<navigator url="reg" open-type="navigate">{{$t('navbar.register')}}</navigator>
						</view>
					</view>
					
				</view>
			</view>
		</view>
		<!-- 	<view class="header">
			<image src="../../static/shilu-login/logo.png"></image>
		</view> -->

		<!-- <view class="list">

			<view class="list-call">
				<image class="img" src="/static/shilu-login/12.png"></image>
				<input class="sl-input" v-model="mobile" type="text" :placeholder="placeholdereml" />
			</view>
			<view class="list-call">
				<image class="img" src="/static/shilu-login/22.png"></image>
				<input class="sl-input" v-model="password" type="text" maxlength="32" :placeholder="placeholderpwd"
					password="true" />
			</view>
		</view>
		<view class="button-login" hover-class="button-hover" @tap="bindLogin()">
			<text style="font-size: 40upx;">{{$t('text.login')}}</text>
		</view>
		<view class="agreenment">
			<navigator url="reg" open-type="navigate">{{$t('navbar.register')}}</navigator>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobile: '',
				password: '',
				openid: '',
				unionid: '',
				userinfowx: '',
				idfd: 1,
				fxpid: 0,
				placeholdereml: this.$t('text.email'),
				placeholderpwd: this.$t('text.input.password')
			};
		},
		onLoad(e) {
			if (e.fxpid) {
				this.fxpid = e.fxpid
				if (e.fxpid > 0) {
					uni.setStorage({
						key: 'fxpid',
						data: e.fxpid
					})
				}
			}
			//#ifdef H5
			var ua = window.navigator.userAgent.toLowerCase();
			if (ua.match(/MicroMessenger/i) == 'micromessenger') {
				this.idfd = 0
				window.open(this.configs.webUrl + '/login.php', "_self")
			}
			//#endif
		},
		methods: {
			// 登录
			async bindLogin() {
				let _this = this
				if (!this.mobile) {
					uni.showToast({
						title: this.$t('text.captcha.youx'),
						icon: "none"
					});
					this.userfocus = true
					return false;
				}
				if (!this.password) {
					uni.showToast({
						title: this.$t('text.captcha.mima'),
						icon: "none"
					});
					this.paswfocus = true
					return false;
				}
				let data = {
					'account': this.mobile,
					'password': this.password
				};
				// #ifdef APP-PLUS
				// var inf = plus.push.getClientInfo();
				// if (inf.clientid) {
				// 	data.clientid = inf.clientid
				// }
				// if (plus.os.name == 'iOS') {
				// 	data.iostoken = inf.token
				// }
				// data.issb = plus.os.name
				// #endif

				if (this.openid) {
					data.openid = this.openid;
				}
				let [err, res] = await this.$httpas.get('/api/user/login', data);

				if (!this.$httpas.errorCheck(err, res)) return;

				if (res.data.code === 1) {
					if (res.data.data.userinfo.avatar) {
						var str = res.data.data.userinfo.avatar;
						if (str.indexOf("data:image") != -1) {
							var avatar = '';
						} else {
							if (str.indexOf("http") != -1) {
								avatar = res.data.data.userinfo.avatar;
							} else {
								avatar = this.configs.imgUrl + res.data.data.userinfo.avatar;
							}
						}
					} else {
						var avatar = '';
					}
					uni.setStorage({ //缓存配置信息
						key: 'avatar',
						data: avatar
					})
					uni.setStorage({ //缓存配置信息
						key: 'userinfo',
						data: res.data.data.userinfo
					})
					uni.setStorage({ //缓存配置信息
						key: 'config',
						data: res.data.data.config
					})
					uni.showLoading({
						title: this.$t('text.dl')
					});
					
					setTimeout(() => {
						let data = {};
						data.token = uni.getStorageSync("userinfo").token;
						uni.request({
							url: this.configs.webUrl + '/api/hyk/hyk_info',
							data: data,
							success: data => {
								console.log('是否为会员', data)
								uni.setStorageSync('Info', data); // 自动转为 
							},
							fail: (data, code) => {}
						})
						uni.hideLoading()
						uni.reLaunch({
							url: '/pages/client/index'
						});
					}, 200)
					// uni.showModal({
					// 	title: '温馨提示',
					// 	content: res.data.msg,
					// 	showCancel: false,
					// 	confirmText: "确定",
					// 	success: function(res) {
					// 		if (res.confirm) {
					// 			//_this.dyxx()

					// 			uni.navigateBack();
					// 		} else if (res.cancel) {

					// 		}
					// 	}
					// });
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: "none"
					});
				}

			},
			
			logins(data) {
				if (data.userinfo.avatar) {
					var str = data.userinfo.avatar;
					if (str.indexOf("data:image") != -1) {
						var avatar = '';
					} else {
						if (str.indexOf("http") != -1) {
							avatar = data.userinfo.avatar;
						} else {
							avatar = this.configs.imgUrl + data.userinfo.avatar;
						}
					}
				} else {
					var avatar = '';
				}
				uni.setStorage({ //缓存配置信息
					key: 'avatar',
					data: avatar
				})
				uni.setStorage({ //缓存配置信息
					key: 'userinfo',
					data: data.userinfo
				})
				uni.setStorage({ //缓存配置信息
					key: 'config',
					data: data.config
				})
				if (this.fxpid > 0) {
					uni.switchTab({
						url: '/pages/client/member/index'
					})
				} else {
					uni.navigateBack();
				}

			},
			opsdd(data) {
				this.userinfowx.openid = this.openid
				uni.setStorage({ //缓存配置信息
					key: 'userinfowx',
					data: this.userinfowx
				})
				var urlsa1 = '/pages/login/loginwxxcx?fxpid=' + this.fxpid
				if (data.dltel) {
					urlsa1 = '/pages/login/loginwxxcx?dltel=' + data.dltel + '&fxpid=' + this.fxpid
				}
				uni.navigateTo({
					url: urlsa1
				})
			},

		}
	}
</script>

<style scoped lang="scss">
	.main_content {
		// padding: 14px 15px;

		.page_content {
			padding-top: 0px;
			// height: 640px;
			position: relative;
			background: #101010;

			.bgsimg {
				// width: 360px;
				position: absolute;
				right: 12rpx;
				// top: 0;
				// left: 0;
				// right: 14px;
			}
		}

		.head_content {
			position: relative;
			top: 30px;
		}

		.main_content {
			position: relative;
			padding: 14px 15px;
			margin-top: 20%;
			.popup_wrap {
				border-radius: 4px;
				border: 1px solid hsla(0, 0%, 100%, .2);
				-webkit-backdrop-filter: blur(24px);
				backdrop-filter: blur(24px);
				background: hsla(0, 0%, 100%, .02);
				position: relative;
				padding: 14px;
			}

			.head_box {
				display: flex;
				flex-direction: row;
				justify-content: space-between;

				.title {
					font-size: 15px;
					color: #fff;
				}
			}

			.input_box {
				margin-top: 14px;

				.type {
					position: absolute;
					top: 0;
					left: 0;
					-webkit-transform: translateY(calc(-100% - 19px));
					transform: translateY(calc(-100% - 19px));
					display: flex;
					align-items: center;

					.item:first-child {
						border-radius: 4px 0 0 4px;
					}

					.item {
						padding: 4px 9px;
						color: #fff;
						font-size: 13px;
						border: 1px solid #fe2a47;
					}

					.active {
						background: #fe2a47;
					}
				}

			}
		}
	}

	.content {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.header {
		width: 161rpx;
		height: 161rpx;
		background: rgba(63, 205, 235, 1);
		box-shadow: 0rpx 12rpx 13rpx 0rpx rgba(63, 205, 235, 0.47);
		border-radius: 50%;
		margin-top: 30rpx;
		margin-left: auto;
		margin-right: auto;
	}

	.header image {
		width: 161rpx;
		height: 161rpx;
		border-radius: 50%;
	}

	.list {
		display: flex;
		flex-direction: column;
		padding-top: 50rpx;
		// padding-left: 70rpx;
		// padding-right: 70rpx;
	}

	.list-call {
		    display: flex;
		    flex-direction: row;
		    justify-content: space-between;
		    align-items: center;
		    height: 48px;
		    color: #fff;
		    border: 0.5px solid #e2e2e2;
		    margin-top: 14px;
		    border-radius: 12rpx;
	}

	.list-call .img {
		width: 40rpx;
		height: 40rpx;
		margin-left: 24rpx;
	}

	.list-call .sl-input {
		flex: 1;
		text-align: left;
		font-size: 32rpx;
		margin-left: 16rpx;
	}

	.button-login {
		color: #FFFFFF;
		font-size: 34rpx;
		// width: 550rpx;
		height: 100rpx;
		background: linear-gradient(90deg, #8134af, #515bd4);
		box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.2);
		border-radius: 12rpx;
		line-height: 100rpx;
		text-align: center;
		margin-left: auto;
		margin-right: auto;
		margin-top: 100rpx;
	}

	.button-hover {
		background: linear-gradient(90deg, #8134af, #515bd4);
	}

	.agreenment {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		font-size: 30rpx;
		margin-top: 80rpx;
		color: #999;
		text-align: center;
		height: 40rpx;
		line-height: 40rpx;
	}

	.agreenment text {
		font-size: 24rpx;
		margin-left: 15rpx;
		margin-right: 15rpx;
	}
</style>